// UpdatingThreads.h
//
#ifndef UPDATINGTHREADS_H
#define UPDATINGTHREADS_H

#include <vector>

#include <QThread>
#include <QQueue>
#include <QMutex>

namespace IDS {
namespace IDEAS {
namespace OpenGLView {

//class GraphicScene;
class VObjectGL;

class ObjectUpdaterThread : public QThread
{
	Q_OBJECT
protected:
	struct Request
	{
		VObjectGL *object;
		double precision;
	};

	struct Operation
	{
		VObjectGL *object;
		int operation;
	};

	QQueue<Operation> opQueue;
	QQueue<Request> queue;
	QMutex mutex;
	//GraphicScene *scene;
	bool running;
	bool updating;
	//void postRefresh();

public:
	ObjectUpdaterThread(/*GraphicScene *s*/);
	~ObjectUpdaterThread();

	// --------------------------------------------------------------------------------------------
	//void enqueueUpdate(unsigned int id, int type,double precision);

	// --------------------------------------------------------------------------------------------
	void enqueueUpdate(VObjectGL *obj ,double precision);

	// --------------------------------------------------------------------------------------------
	void enqueueUpdate(std::vector<VObjectGL*> &objs,double precision);

	// --------------------------------------------------------------------------------------------
	void enqueueOperation(VObjectGL *obj, int op);
	
	// --------------------------------------------------------------------------------------------
	void run();

	// --------------------------------------------------------------------------------------------
	void start();
	void stop();

	//VObjectGL *currentWorkingObject();
	bool isUpdating() {return updating;}
	void resetUpdating() {updating = false;}

//signals:
//	void refreshView();
};

}}}


#endif